/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler.fixtures;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import se392.ateam2006.meetingmgmt.MeetingMgmtRemote;
import se392.ateam2006.meetingmgmt.meeting.MeetingEntity;
import se392.ateam2006.resourcemgmt.ResourceMgmtRemote;
import se392.ateam2006.resourcemgmt.participant.exclusionset.ExclusionRangeEntity;
import se392.ateam2006.user.UserEntity;
import se392.ateam2006.user.UserMgmtRemote;

/**
 *
 * @author Caroline
 */
public class PreferenceSetForParticipant extends fit.RowFixture {

    private UserMgmtRemote userManage;
    private ResourceMgmtRemote resourceManage;
    private String email;

    public PreferenceSetForParticipant(UserMgmtRemote userManage, ResourceMgmtRemote resourceManage, String email) {
        this.userManage = userManage;
        this.resourceManage = resourceManage;
        this.email = email;
    }

    @Override
    public Object[] query() throws Exception {
        UserEntity user = userManage.getUserByID(email);
        if (user != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd kk:mm");
            ArrayList exclusionList = new ArrayList();
            Collection<ExclusionRangeEntity> exclusions = resourceManage.getExclusionSetsForParticipant(user);
            for (ExclusionRangeEntity ex : exclusions) {
                if (ex.isPreferenceSet()) {
                    exclusionList.add(new ExclusionRangeEntityMeetingShell(
                            ex.getMeeting().getId(),
                            format.format(ex.getStartDate().getTime()),
                            format.format(ex.getEndDate().getTime())));
                }
            }
            return exclusionList.toArray();
        }
        System.err.println("Couldn't find user " + email);
        return null;
    }

    @Override
    public Class getTargetClass() {
        return ExclusionRangeEntityMeetingShell.class;
    }
}
